﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Toybox.NicoSharp.RSS
{
	using Extensions;
	using Primitives;
	using Utilities;

	[XmlRoot("rss")]
	public class TagRSS : AbstractRSSwithAtomLink
	{

		#region [Static]

		public static TagRSS Get(string tag, VideoSortType sortType = VideoSortType.CommentDate, OrderType orderType = OrderType.Desc)
		{
			string url = NicoUrls.VideoTop + "tag/" + Uri.EscapeUriString(tag);
			return Get<TagRSS>(url + "?" + GetQuery(sortType, orderType));
		}

		protected static string GetQuery(VideoSortType sortType, OrderType orderType)
		{
			Dictionary<string, string> query = new Dictionary<string, string>();

			if (sortType != VideoSortType.CommentDate)
				query.Add("sort", sortType.ToSign());

			if (orderType == OrderType.Asc)
				query.Add("order", "a");

			query.Add("rss", "2.0");

			return Serializer.AndEqualPairSerializer(query);
		}

		#endregion [Static]


		#region Public Members

		public Channel channel;

		#endregion Public Members


		#region [SubClass]

		public class Channel : AbstractChannel
		{
			/// <summary>
			/// AtomLink
			/// </summary>
			[XmlElement(ElementName = "link", Namespace = AtomLink.NAMESPACE)]
			public AtomLink atomlink;

			/// <summary>
			/// 日時
			/// </summary>
			public string pubDate;

			/// <summary>
			/// 生成日時
			/// </summary>
			public string lastBuildDate;

			/// <summary>
			/// RSS生成者
			/// </summary>
			public string generator;

			public string docs;

			/// <summary>
			/// アイテム
			/// </summary>
			[XmlElement]
			public Item[] item;
		}

		#endregion [SubClass]

	}
}
